import optionsx from '@/Echarts/柱状图'
import * as echarts from 'echarts'
let options = JSON.parse(JSON.stringify(optionsx))
// const { echarts } = window

export default (element, data) => {
  const old = echarts.getInstanceByDom(element)
  if (old) old.dispose()
  const chart = echarts.init(element, 'theme')
  // eslint-disable-next-line no-unused-vars
  if (data.data1) {
    options = {
      title: [
        {
          left: '5%',
          top: 30,
          textStyle: { color: 'white', fontSize:12},
          text: '种植面积排名(万亩)'
        }, {
          top: 30,
          left: '38%',
          textStyle: { color: 'white', fontSize:12},
          text: '种植产量排名(万吨)'
        }, {
          top: 30,
          left: '70%',
          textStyle: { color: 'white', fontSize:12},
          text: '综合产值排名(亿元)'
        }
      ],
      grid: [
        { left: '10%', right: '66%', bottom: '1%', show: false, containLabel: true },
        { left: '43%', right: '33%', bottom: '1%', show: false, containLabel: true },
        { left: '76%', right: '0%', bottom: '1%', show: false, containLabel: true }
      ],
      tooltip: {
        trigger: 'axis',
        axisPointer: { // 坐标轴指示器，坐标轴触发有效
          type: 'line' // 默认为直线，可选为：'line' | 'shadow'
        }
      },
      toolbox: {
        show: false,
        orient: 'vertical',
        x: 'right',
        y: 'center',
        feature: {
          mark: true,
          dataView: { readOnly: false },
          restore: true,
          saveAsImage: true
        }
      },
      calculable: true,
      xAxis: [
        {
          type: 'value',
          splitLine: { show: false },
          axisLine: { show: false },
          axisTick: { show: false },
          axisLabel: { show: false },
          gridIndex: 0
        },
        {
          type: 'value',
          splitLine: { show: false },
          axisLine: { show: false },
          axisTick: { show: false },
          axisLabel: { show: false },
          gridIndex: 1
        },
        {
          type: 'value',
          splitLine: { show: false },
          axisLine: { show: false },
          axisTick: { show: false },
          axisLabel: { show: false },
          gridIndex: 2
        }
      ],
      yAxis: [
        {
          type: 'category',
          axisLine: { show: false },
          axisTick: { show: false },
          splitArea: { show: false },
          data: data.data1,
          gridIndex: 0

        },
        {
          type: 'category',
          axisLine: { show: false },
          axisTick: { show: false },
          splitArea: { show: false },
          data: data.data2,
          gridIndex: 1

        },
        {
          type: 'category',
          axisLine: { show: false },
          axisTick: { show: false },
          splitArea: { show: false },
          data: data.data3,
          gridIndex: 2

        }
      ],
      series: [
        {
          name: '面积',
          type: 'bar',
          data: data.data4,
          barWidth: '60%',
          label: {
            normal: {
              show: true,
              position: 'insideLeft',
              textStyle: {
                color: '#fff',
              },
            },
          },
          xAxisIndex: 0, yAxisIndex: 0
        },
        {
          name: '产量',
          type: 'bar',
          data: data.data5,
          barWidth: '60%',
          label: {
            normal: {
              show: true,
              position: 'insideLeft',
              textStyle: {
                color: '#fff',
              },
            },
          },
          xAxisIndex: 1, yAxisIndex: 1
        },
        {
          name: '产值',
          type: 'bar',
          data: data.data6,
          barGap: 15,
          barWidth: '60%',
          label: {
            normal: {
              show: true,
              position: 'insideLeft',
              textStyle: {
                color: '#fff',
              },
            },
          },
          xAxisIndex: 2, yAxisIndex: 2
        }
      ]
    };
  }
  chart.setOption(options)
  return chart
}
